home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000003_icon-group-sender _Wed Jun 30 17:07:59 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
3KB
Received: from owl.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Wed, 30 Jun 1993 18:03:29 MST
Received: by owl.cs.arizona.edu; Wed, 30 Jun 1993 18:03:28 MST
Date: Wed, 30 Jun 93 17:07:59 -0700
From: wgg@cs.ucsd.edu (William Griswold)
Message-Id: <9307010007.AA04348@gremlin>
To: abrahams@acm.org, icon-group@cs.arizona.edu
Subject: Re: Tables versus lists
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
Paul,
Arrays in Icon are allocated in segments that double the size of the
array, so that look ups are on average logarithmic in time for random
access. The logarithmic behavior does not show up until arrays are
rather large. Array elements are generated in constant time.
Table elements are generated in basically constant time up to a certain
size, whereafter you will see a linear degradation. The degradation
point depends on the implementation, but it is rarely a concern for
the programmer.
I would use arrays and switch later if necessary. Since their syntax
is very similar for most operations, making the change should not be
difficult. If it would be, you could encapsulate the syntax of the
data structure accesses with procedures.
In fact, you don't need to know the implementation in most cases:
a simple statement of the computational complexity of key operations
is sufficient.
Bill Griswold
UCSD
>From: Paul_Abrahams@MTS.cc.Wayne.edu
>
>Suppose that I have a "growing array" whose elements I frequently
>reference. I can implement that array in Icon in either of two ways: as
>a list or as a table. The construct for referencing an array element is
>the same in either case: array[n]. The constructs for adding an element
>are different, but not that different:
> push(array, element)
>versus
> array[integer(*array+1)] := element
>
>My question is: how do the efficiencies of these constructs compare? I
>know that lists are implemented efficiently if allocated all at once, but
>how about the case where they grow an element at a time? If finding an
>element requires a search down a linked list with hundreds of items, the
>table is clearly preferable; but if finding an element in the list can be
>done with an integer-indexed lookup, the list is clearly preferable.
>
>This is a good example of a choice in Icon that is difficult to make
>intelligently without a knowledge of the implementation and that can make
>a great difference in performance.
>
>Paul Abrahams
>Reply-To: abrahams@acm.org